-----------------------------------------
-- Spell: Slow
-- Spell accuracy is most highly affected by Enfeebling Magic Skill, Magic Accuracy, and MND.
-- Slow's potency is calculated with the formula (150 + dMND*2)/1024, and caps at 300/1024 (~29.3%).
-- And MND of 75 is neccessary to reach the hardcap of Slow.
-----------------------------------------

require("scripts/globals/status");
require("scripts/globals/magic");

-----------------------------------------
-- OnSpellCast
-----------------------------------------

function OnMagicCastingCheck(caster,target,spell)
	return 0;
end;

function onSpellCast(caster,target,spell)

	dMND = (caster:getStat(MOD_MND) - target:getStat(MOD_MND));
	bonus = AffinityBonus(caster,spell);

	--Power.
	power = 150 + dMND * 2;
	if(power > 300) then
		power = 300;
	end

	--Duration, including resistance.
	duration = 120 * applyResistance(caster,spell,target,dMND,35,bonus);
	if(100 * math.random() >= target:getMod(MOD_SLOWRES)) then
		if(duration >= 60) then --Do it!

			if(target:addStatusEffect(EFFECT_SLOW,power,0,duration)) then
				spell:setMsg(236);
			else
				spell:setMsg(75);
			end

		else
			spell:setMsg(85);
		end
	else
		spell:setMsg(85);
	end

	return EFFECT_SLOW;
end;